package com.zline.foodraise.view;

import android.content.Context;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.makeramen.roundedimageview.RoundedImageView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.zline.foodraise.R;
import com.zline.foodraise.constant.Constant;
import com.zline.foodraise.listener.RecyclerItemClicked;
import com.zline.foodraise.util.ImageUtil;

import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

import java.util.zip.CheckedOutputStream;

/**
 * Created by heshantao on 15/8/1.
 * 评论列表中图片列表Item
 */
@EViewGroup(R.layout.comment_list_item_pics_item)
public class CommentListItemPicsItem extends RelativeLayout {
    private static final String LOG_TAG = CommentListItemPicsItem.class.getSimpleName();
    @ViewById(R.id.comment_list_pic_item_iv)
    RoundedImageView iv;
    @Bean
    ImageUtil imageUtil;
    DisplayImageOptions options;
    ImageLoader imageLoader;
    int position;
    RecyclerItemClicked itemClicked;
    int parentPosition;
    int parentFlag;

    public CommentListItemPicsItem(Context context) {
        super(context);
    }

    public void bind(int flag,String url,int position,int parentPosition,DisplayImageOptions options) {
        this.position=position;
        this.parentPosition=parentPosition;
        this.parentFlag=flag;
        imageLoader = ImageLoader.getInstance();
        imageLoader.displayImage(url, iv, options);
    }

    public void setListener(RecyclerItemClicked listener){
        this.itemClicked=listener;

    }

    @Click(R.id.comment_list_pic_item_rl)
    void onClick(){
        int sonFlag=-1;
        if(parentFlag==Constant.COMMENT_FLAG){
            sonFlag=Constant.COMMENT_LIST_PICS_FLAG;
        }else if(parentFlag==Constant.HOT_COMMENT_FLAG){
            sonFlag=Constant.HOT_COMMENT_LIST_PICS_FLAG;
        }else if(parentFlag==Constant.DETAIL_DYNAMIC_COMMENT_FLAG){
            sonFlag= Constant.DETAIL_DYNAMIC_COMMENT_LIST_PICS_FLAG;
        }
        if(parentPosition<0){
            itemClicked.onRecyclerItemClicked(sonFlag,position);
        }else{
            itemClicked.onRecyclerItemClicked(sonFlag,position,parentPosition);
        }
    }
}
